/**
 * Copyright 2014-2015 www.fsfkj.com
 * All rights reserved.
 * 
 * @project
 * @author Flouny.Caesar
 * @version 1.0
 * @date 2015-09-11
 */
package com.eyaomall.wxmall.common.helper.sms;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lycheeframework.core.cmp.api.error.SECode;
import com.lycheeframework.core.common.util.StringUtil;
import com.lycheeframework.core.exception.ErrorCodeException;

/**
 * 发送短信工具类
 * @author Flouny.Caesar
 *
 */
public class SMSHelper {
	
	private static final Logger LOG = LoggerFactory.getLogger(SMSHelper.class);
	
	/**
	 * 发送短信
	 * @param phone
	 * @param content
	 * @return
	 */
	public static void sendSMS(String phone, String content) {
		if (StringUtil.isBlank(phone) || StringUtil.isBlank(content)) 
			throw new ErrorCodeException(SECode.s_100010);
		
		String ct = getURL(phone, content);
		LOG.info("----------- sms content: " + ct + " -----------");
		LOG.info("----------- " + HttpSend.getSend(ct,null) + " -----------");
	}
	
//	private static String getURL(String phone, String content) {
//		StringBuffer buffer = new StringBuffer();
//		buffer.append("account=");
//		buffer.append("002011");
//		buffer.append("&pswd=");
//		buffer.append("Sy002011");
//		buffer.append("&mobile=");
//		buffer.append(phone);
//		buffer.append("&needstatus=");
//		buffer.append(true);
//		buffer.append("&msg=");
//		buffer.append(content);
//		
//		return buffer.toString(); 
//}
	
	private static String getURL(String phone, String content) {
		StringBuffer buffer = new StringBuffer();
		buffer.append("http://jiekou.56dxw.com/sms/HttpInterface.aspx?");
		buffer.append("comid=");
		buffer.append("2520");
		buffer.append("&username=");
		buffer.append("fsfkj");
		buffer.append("&userpwd=");
		buffer.append("1smn9o1m");
		buffer.append("&handtel=");
		buffer.append(phone);
		buffer.append("&sendcontent=");
		try {
			buffer.append(URLEncoder.encode("【找房吧】".concat(content), "gbk"));
		} catch (UnsupportedEncodingException e) {
			// ...
		}
		buffer.append("&sendtime=&smsnumber=");
		buffer.append("10690");
		
		return buffer.toString(); 
	}
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		SMSHelper.sendSMS("13989452970", "您好！您的验证码是：123456");
	}
}